{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>当前页面针对入驻申请进行管理，可以针入驻申请进行审核认证，审核支付操作。</li>
			<li>入驻流程：会员申请->审核认证信息->会员上传支付凭据->审核支付信息->审核通过后入驻。</li>
		</ul>
	</div>
</div>

<div class="ns-screen layui-collapse" lay-filter="selection_panel">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">筛选</h2>
		<form class="layui-colla-content layui-form layui-show">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">主营行业：</label>
					<div class="layui-input-inline">
						<select name="category_id" lay-filter="category_id">
							<option value="">请选择主营行业</option>
							{volist name="$shop_category_list" id="category"}
							<option value="{$category.category_id}">{$category.category_name}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">开店套餐：</label>
					<div class="layui-input-inline">
						<select name="group_id" lay-filter="group_id">
							<option value="">请选择开店套餐</option>
							{volist name="$shop_group_list" id="group"}
							<option value="{$group.group_id}">{$group.group_name}</option>
							{/volist}
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">店铺名称：</label>
					<div class="layui-input-inline">
						<input type="text" id="search_text" name="search_text" placeholder="店铺名称" autocomplete="off" class="layui-input">
					</div>
				</div>
				
				<div class="layui-inline">
					<label class="layui-form-label">申请账号：</label>
					<div class="layui-input-inline">
						<input type="text" id="search_text_user" name="search_text_user" placeholder="申请账号" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">申请时间：</label>
					<div class="layui-input-inline">
					    <input type="text" class="layui-input" name="start_time"  id="start_time" autocomplete="off" placeholder="开始时间" readonly>
						<i class="ns-calendar"></i>
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline">
					    <input type="text" class="layui-input" name="end_time" id="end_time" autocomplete="off" placeholder="结束时间" readonly>
						<i class="ns-calendar"></i>
					</div>
				</div>
			</div>
			<input type="hidden" name="apply_state" />
			<div class="ns-form-row">
				<button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</form>
	</div>
</div>
<div class="layui-tab ns-table-tab" lay-filter="apply_list_tab">
	<ul class="layui-tab-title">
		<li class="layui-this" lay-id="">全部</li>
		<li lay-id="1" data-type="apply_state">待认证审核</li>
		<li lay-id="-1" data-type="apply_state">认证审核失败</li>
		<li lay-id="4" data-type="apply_state">待提交财务凭证</li>
		<li lay-id="2" data-type="apply_state">待财务审核</li>
		<li lay-id="3" data-type="apply_state">财务审核成功</li>
		<li lay-id="-2" data-type="apply_state">财务审核失败</li>
	</ul>
	<div class="layui-tab-content">
		<!-- 列表 -->
		<table id="apply_list" lay-filter="apply_list"></table>
	</div>
</div>
<!-- 列表 -->

<!-- 工具栏操作 -->
<script type="text/html" id="operation">
	<div class="ns-table-btn">
		{{#  if(d.apply_state == 1){ }}
		<a class="layui-btn" lay-event="apply_pass">同意申请</a>
		<a class="layui-btn" id="apply_message" lay-event="apply_refuse">拒绝申请</a>
		<a class="layui-btn" lay-event="apply_detail">认证信息</a>
		{{#  } }}
		{{#  if(d.apply_state == -1){ }}
		<a class="layui-btn" lay-event="apply_detail">认证信息</a>
		{{#  } }}
		{{#  if(d.apply_state == 2){ }}
			{{#  if(d.paying_money_certificate){ }}
			<a class="layui-btn" lay-event="edit_apply">支付信息</a>
			{{# } }}
		<a class="layui-btn" lay-event="apply_detail">认证信息</a>
		{{#  } }}
		{{#  if(d.apply_state == 3){ }}
		<a class="layui-btn" lay-event="apply_detail">认证信息</a>
		<a class="layui-btn" lay-event="edit_apply">支付信息</a>
		{{#  } }}
		{{#  if(d.apply_state == -2){ }}
		<a class="layui-btn" lay-event="edit_apply">财务拒绝</a>
		<a class="layui-btn" lay-event="apply_detail">认证信息</a>
		{{#  } }}
	</div>
</script>

<!-- 申请状态 -->
<script type="text/html" id="apply_state_name">
	{{#  if(d.apply_state == -1){ }}
	<span style="color: gray;">认证审核失败</span>
	{{#  } }}
	{{#  if(d.apply_state == 1){ }}
	<span style="color: red;">待认证审核</span>
	{{#  } }}
	{{#  if(d.apply_state == 2){ }}
		{{#  if(d.paying_money_certificate){ }}
		<span style="color: blue;">待财务审核</span>
		{{#  }else{ }}
		<span style="color: blue;">待提交财务凭证</span>
		{{#  } }}
	{{#  } }}
	{{#  if(d.apply_state == 3){ }}
	<span style="color: green;">财务审核成功</span>
	{{#  } }}
	{{#  if(d.apply_state == -2){ }}
	<span style="color: gray;">财务审核失败</span>
	{{#  } }}
</script>
{/block}
{block name="script"}
<script>
	var element;
	layui.use(['form', 'layer', 'laydate', 'element'], function() {
		var table,
			form = layui.form,
			layer = layui.layer,
			element = layui.element,
			laydate = layui.laydate;
		form.render();

		//渲染时间
		laydate.render({
			elem: '#start_time',
			type: 'datetime'
		});
		
		laydate.render({
			elem: '#end_time',
			type: 'datetime'
		});
		//监听Tab切换，以改变地址hash值
		element.on('tab(apply_list_tab)', function () {
			var type = this.getAttribute('data-type');
			if (type) {
				var id = this.getAttribute('lay-id');
				$("input[name='" + type + "']").val(id);
				$("button[lay-filter='search']").click()
			} else {
				$("input[name='apply_state']").val("");
				$("button[lay-filter='search']").click()
			}
		});
		/**
		 * 表格加载
		 */
		table = new Table({
			elem: '#apply_list',
			url: ns.url("city://city/shopapply/apply"),
			parseData: function(res) { //res 即为原始返回的数据
				return {
					"code": res.code, //解析接口状态
					"msg": res.message, //解析提示文本
					"count": res.data.count, //解析数据长度
					"data": res.data.list //解析数据列表
				};
			},
			cols: [
				[ //表头
					{
						width:'12%',
						field: 'shop_name',
						title: '店铺名称',
						unresize: 'false',
					}, {
						width:'10%',
						field: 'group_name',
						title: '开店套餐',
						unresize: 'false',
					}, {
						width:'10%',
						field: 'category_name',
						title: '主营行业',
						unresize: 'false',
					}, {
						width:'10%',
						field: 'username',
						title: '申请账号',
						unresize: 'false',
					}, {
						width:'8%',
						field: 'apply_year',
						title: '入驻时长',
						unresize: 'false',
						templet: function(data) {
							return data.apply_year+'年';
						},
					}, {
						width:'13%',
						field: 'paying_amount',
						title: '<span title="入驻费用" style="padding-right: 15px;">入驻费用</span>',
						unresize: 'false',
						align: 'right',
						templet: function(data) {
							return '<span title="'+ data.paying_amount +'" style="padding-right: 15px;">￥'+ data.paying_amount +'</span>';
						},
					}, {
						width:'9%',
						field: 'apply_state_name',
						title: '申请状态',
						unresize: 'false',
						templet: '#apply_state_name',
					},  {
						width:'13%',
						field: 'create_time',
						title: '申请时间',
						unresize: 'false',
						templet: function(data) {
							return ns.time_to_date(data.create_time);
						},
					}, {
						width:'15%',
						title: '操作',
						toolbar: '#operation',
						unresize: 'false'
					}
				]
			]
		});
		
		/**
		 * 搜索功能
		 */
		form.on('submit(search)', function(data) {
			table.reload({
				page: {
					curr: 1
				},
				where: data.field
			});
			return false;
		});
		
		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data,
				event = obj.event;
			switch (event){  
				case 'apply_pass':  //审核通过
				layer.confirm('确定要通过审核吗?', function() {
				$.ajax({
						url: ns.url("city://city/shopapply/applyPass"),
						data: {
							"apply_id":data.apply_id,
						},
						dataType: 'JSON', //服务器返回json格式数据
						type: 'POST', //HTTP请求类型
						success: function(res) {
							layer.msg(res.message);
							if (res.code == 0) {
								table.reload();
							}
						}
					});
				});
				break;
				
				case 'apply_refuse':  //拒绝
				/**
				 * 拒绝理由弹窗
				 */
					layer.prompt({
						formType: 2,
						value: '',
						title: '请输入拒绝理由',
						area: ['300px', '100px'] ,//自定义文本域宽高
						yes: function(index, layero){
							// 获取文本框输入的值
							var value = layero.find(".layui-layer-input").val();
							if (value) {
								$.ajax({
									url: ns.url("city://city/shopapply/applyReject"),
									data: {
										"apply_id":data.apply_id,
										"reason":value
									},
									dataType: 'JSON', //服务器返回json格式数据
									type: 'POST', //HTTP请求类型
									success: function(res) {
										layer.msg(res.message);
										if (res.code == 0) {
											table.reload();
										}
									}
								});
								layer.close(index);
							} else {
								layer.msg('请输入拒绝原因!', {icon: 5, anim: 6});
								return;
							}
						}
					}); 
					
					break;
				case 'apply_detail':  //认证信息
				location.href = ns.url("city://city/shopapply/applyDetail?apply_id=" +data.apply_id)
					break;
				case 'open_shop':  //入驻通过
				layer.confirm('确定要通过他的入驻申请吗?', function() { 
					$.ajax({
						url: ns.url("city://city/shopapply/openShop"),
						data: {
							"apply_id":data.apply_id,
						},
						dataType: 'JSON', //服务器返回json格式数据
						type: 'POST', //HTTP请求类型
						success: function(res) {
							layer.msg(res.message);
							if (res.code == 0) {
								table.reload();
							}
						}
					});
				});
					break;
					case 'edit_apply' : //修改资料
				location.href = ns.url("city://city/shopapply/editApply?apply_id=" +data.apply_id)
			}
		});
		
	});
	
	function clickAdd() {
		location.href = ns.url("city://city/shopapply/addShop");
	}
</script>
{/block}